

clear all;
clc;
close all;


input_size= [0.035 70.5 182.3 347.0 607.2]; 
time_b= [0.01 62.76 470.59 1809.97 5492.77];
time_h=[0.01 0.86 2.44 4.93 8.84];
time_h_asm=[0.00 0.88 2.48 4.93 8.76];

%***************************** tiempo de ejecucion bublesort, heapsort C, heapsort asm **************************

% Create a vertical bar chart using the bar function
figure1 = figure;

axes1 = axes('Parent',figure1,'YScale','log','YMinorTick','on',...
    'XTickLabel',{'70.5','182.3','347.0','607.2'},...
    'XTick',[70.5 182.3 347 607.2]);

% Set the axis limits
 xlim(axes1,[0 700]);
 ylim(axes1,[0.8 6000]);
 box(axes1,'on');
 hold(axes1,'all');


bar1 = bar(input_size(2:5), [time_b(2:5)' time_h(2:5)' time_h_asm(2:5)'], 1,'BaseValue',1,'Parent',axes1);

% Add title and axis labels
title('Comparación de los tiempos de ejecución de Bubble sort, Heap sort en C y en Assembly (Semilog).');
set(bar1(1),'DisplayName','Bubble sort');
set(bar1(2),'DisplayName','Heap sort en C');
set(bar1(3),'DisplayName','Heap sort en Assembly');
set(bar1(1),'FaceColor',[1 0 0]);
set(bar1(2),'FaceColor',[0 0 1]); 
set(bar1(3),'FaceColor',[0 1 0]);


% Create xlabel
xlabel(axes1, 'Tamaño del archivo (en KBytes)');

% Create ylabel
ylabel(axes1, 'Tiempo (en segundos)');

% Add a legend
legend(axes1, 'Bubble sort', 'Heap sort en C', 'Heap sort en Assembly');

% Create legend
legend1 = legend(axes1,'show');
set(legend1,...
    'Position',[0.1394912745705 0.765911317058468 0.322321428571429 0.136309523809524]);
 
 %*****************************************************************************************************

 
 
 %***************************** tiempo de ejecucion heapsort C, heapsort asm **************************

% Create a vertical bar chart using the bar function
figure2 = figure;

axes2 = axes('Parent',figure2,'YScale','log','YMinorTick','on',...
    'XTickLabel',{'70.5','182.3','347.0','607.2'},...
    'XTick',[70.5 182.3 347 607.2]);

% Set the axis limits
 xlim(axes2,[0 700]);
 ylim(axes2,[0.8 10]);
 box(axes2,'on');
 hold(axes2,'all');


bar2 = bar(input_size(2:5), [time_h(2:5)' time_h_asm(2:5)'], 1,'BaseValue',1,'Parent',axes2);

% Add title and axis labels
title('Comparación de los tiempos de ejecución de Heap sort en C y en Assembly (Semilog).');
set(bar2(1),'DisplayName','Heap sort en C');
set(bar2(2),'DisplayName','Heap sort en Assembly');
set(bar2(1),'FaceColor',[0 0 1]);
set(bar2(2),'FaceColor',[0 1 0]); 


% Create xlabel
xlabel(axes2, 'Tamaño del archivo (en KBytes)');

% Create ylabel
ylabel(axes2, 'Tiempo (en segundos)');

% Add a legend
legend(axes2, 'Heap sort en C', 'Heap sort en Assembly');

% Create legend
legend2 = legend(axes2,'show');
set(legend2,...
    'Position',[0.1394912745705 0.765911317058468 0.322321428571429 0.136309523809524]);
 
%*****************************************************************************************************



%***************************** tiempo de ejecucion bublesort, heapsort asm ***************************

% Create a vertical bar chart using the bar function
figure3 = figure;

axes3 = axes('Parent',figure3,'YScale','log','YMinorTick','on',...
    'XTickLabel',{'70.5','182.3','347.0','607.2'},...
    'XTick',[70.5 182.3 347 607.2]);

% Set the axis limits
 xlim(axes3,[0 700]);
 ylim(axes3,[0.8 6000]);
 box(axes3,'on');
 hold(axes3,'all');


bar3 = bar(input_size(2:5), [time_b(2:5)' time_h_asm(2:5)'], 1,'BaseValue',1,'Parent',axes3);

% Add title and axis labels
title('Comparación de los tiempos de ejecución de Bubble sort y Heap sort en Assembly (Semilog).');
set(bar3(1),'DisplayName','Bubble sort');
set(bar3(2),'DisplayName','Heap sort en Assembly');
set(bar3(1),'FaceColor',[1 0 0]);
set(bar3(2),'FaceColor',[0 1 0]);



% Create xlabel
xlabel(axes3, 'Tamaño del archivo (en KBytes)');

% Create ylabel
ylabel(axes3, 'Tiempo (en segundos)');

% Add a legend
legend(axes3, 'Bubble sort', 'Heap sort en Assembly');

% Create legend
legend1 = legend(axes3,'show');
set(legend1,...
    'Position',[0.1394912745705 0.765911317058468 0.322321428571429 0.136309523809524]);
 
%*****************************************************************************************************
 


%***************************** Speedup de heapsort respecto a bubblesort *****************************

 % calculos de speed up su=Told/Tnew=time_b/time_h;
  
 
 su1= zeros(size(input_size(2:5))); % inicializo en 0 el vector
  
 for i=2:5
         su1(i-1)= time_b(i)/time_h(i);             
 end


% 
figure4 = figure;

axes4 = axes('Parent',figure4,'YMinorTick','on',...
    'XTickLabel',{'70.5','182.3','347.0','607.2'},...
    'XTick',[70.5 182.3 347 607.2]);

% Set the axis limits
 xlim(axes4,[0 700]);
 ylim(axes4,[0 650]);
 box(axes4,'on');
 hold(axes4,'all');

stem(axes4, input_size(2:5), su1,'Color',[1 0 0]);
% Add title and axis labels
title('SpeedUp de Heap sort respecto a Bubble sort.');

% Create xlabel
xlabel(axes4, 'Tamaño del archivo (en KBytes)');

% Create ylabel
ylabel(axes4, 'SpeedUp');

 
%*****************************************************************************************************
 


%***************************** Speedup de heapsort asm respecto a heapsort C **************************

 % calculos de speed up su=Told/Tnew= time_h/time_h_asm;


su2= zeros(size(input_size(2:5))); % inicializo en 0 el vector
  
 for i=2:5
         su2(i-1)= time_h(i)/time_h_asm(i);             
 end


% 
figure5 = figure;

axes5 = axes('Parent',figure5,'YMinorTick','on',...
    'XTickLabel',{'70.5','182.3','347.0','607.2'},...
    'XTick',[70.5 182.3 347 607.2]);

% Set the axis limits
 xlim(axes5,[0 700]);
 ylim(axes5,[0 1.1]);
 box(axes5,'on');
 hold(axes5,'all');

stem(axes5, input_size(2:5), su2,'Color',[0 0.498039215803146 0]);
% Add title and axis labels
title('SpeedUp de Heap sort asm respecto a Heap sort C.');

% Create xlabel
xlabel(axes5, 'Tamaño del archivo (en KBytes)');

% Create ylabel
ylabel(axes5, 'SpeedUp');

hold on;

plot1=plot(0:700, ones(701));
set(plot1(701),'Color',[0 0.749019622802734 0.749019622802734]);
 
 %*****************************************************************************************************
 






 
 
